﻿@{
    ViewBag.Title = "电子杂志";
    Layout = "~/Views/Shared/_ViewFormPage.cshtml";
}
@model DocumentVM
@section head{
    <meta name="viewport" content="initial-scale=1,user-scalable=no,maximum-scale=1,width=device-width" />

    <script src="/Scripts/FlexPaper/js/flexpaper.js?@CommonSetting.JsVersion"></script>
    <script src="/Scripts/FlexPaper/js/flexpaper_handlers.js?@CommonSetting.JsVersion"></script>
    <link href="/Scripts/FlexPaper/css/flexpaper.css?@CommonSetting.JsVersion" rel="stylesheet" />
    <script src="/Scripts/AjaxFileUploaderV2.1/ajaxfileupload.js"></script>
    <script type="text/javascript">

        function save() {
            if ($("form").valid()) {
                $('form').ajaxSubmit({
                    beforeSubmit: function () {
                        $("#btnSave").off("click", save);
                    },
                    success: function (callback) {
                        if (callback) {
                            $.ligerDialog.success('保存成功', function (yes) {
                                self.location.href = "/EZine/EZine";
                            });
                        }
                        else {
                            $("#btnSave").on("click", save);
                            $.ligerDialog.error('保存失败');
                        }
                    },
                    error: function (ex) {
                        $("#btnSave").on("click", save);
                        $.ligerDialog.error('保存失败');
                    }

                });
            }
        }


        $(function () {
            $("#btnSave").on("click", save);


            $("#btnCancel").click(function (e) {
                deleteFile();
            });
            $("#btnUpload").click(function (e) {
                e.preventDefault();
                ajaxFileUpload();
            });

        });


        function ajaxFileUpload() {
            var dialog = $.ligerDialog.waitting('正在上传,请稍候...');
            $.ajaxFileUpload({
                url: '/File/Upload',
                secureuri: false,
                fileElementId: 'imgFile',
                dataType: 'json',
                cache: false,
                data: { dir: 'onlinefile', localUrl: '' },
                success: function (data, status) {
                    if (typeof (data.error) !== 'undefined') {
                        if (data.error === 0) {
                            deleteFile();
                            $("#preFile").val(data.url);
                            $("#DocUrl").val(data.url);
                            try {
                                getDocViewer().loadSwf($("#preFile").val());
                            } catch (e) {

                            }

                        } else {
                            $.ligerDialog.error('上传出错:' + data.message);
                        }
                    }
                },
                error: function (data, status, e) {
                    $.ligerDialog.error('上传出错:' + e);
                }
                ,
                complete: function (XMLHttpRequest, textStatus) {
                    dialog.close();
                }
            })
            return false;
        }



        var docViewer;
        function getDocViewer() {
            if (docViewer) {
                return docViewer;
            }
            else {
                docViewer = window.FlexPaperViewer_InstancedocumentViewer.getApi();
            }

            return docViewer;
        }

        function deleteFile() {
            if ($("#preFile").val() != "") {
                $.ajax({
                    url: '/File/Delete',
                    type: 'POST',
                    data: { filePath: $("#preFile").val() },
                    cache: false,
                    success: function (data) {
                    },
                });

            }
        }

    </script>
    @if (false)
    {
        <script src="/Scripts/jquery-1.8.2.js"></script>
    }
    <style type="text/css">
    </style>
}
<div id="header" class="header">
    <h4>电子杂志 -- 添加</h4>
</div>
@using (Html.BeginForm("EZine", "EZine", FormMethod.Post))
{
    @Html.HiddenFor(model => model.CompanyId)
    @Html.HiddenFor(model => model.Id)
     @Html.HiddenFor(model => model.UploadDate)
    <div id="detail_forms">
        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                名称
            </div>
            <div class="formItem textItem">
                @Html.TextBoxFor(model => model.Title, new { @class = "texts" })
            </div>
            <div class="formItem msgItem">
                *
            </div>
        </div>
        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                简述
            </div>
            <div class="formItem textItem">
                @Html.TextAreaFor(model => model.Intro, new { @class = "ifunny-textareas" })
            </div>
            <div class="formItem msgItem">
            </div>
        </div>
        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                图片
            </div>
            <div class="formItem textItem">
                <table border="0">
                    <tr>
                        <td style="height:40px;">
                            <input type="file" id="imgFile" name="imgFile" />
                            <span class="buttons">
                                <a href="javascript:void(0);" id="btnUpload">上传PDF文件</a>
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td style="vertical-align: bottom;">
                            <div style="width: 220px; margin-left: 10px; display: block">
                                <input type="file" id="fileUploader" style="display: none;" name="file_upload" />
                                @Html.HiddenFor(m => m.DocUrl)
                                @Html.Hidden("preFile")
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="formItem msgItem">
            </div>
        </div>

        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                预览
            </div>
            <div class="formItem textItem">
                <div id="documentViewer" class="flexpaper_viewer" style="width: 670px; height: 360px; border: 1px solid #ccc;"></div>
            </div>
            <div class="formItem msgItem">
            </div>
        </div>
        <div id="btnContainer" class="formsItems">
            <div class="formItem labelItem">
                &nbsp;
            </div>
            <div class="formItem textItem">
                <a href="javascript:void(0);" id="btnSave">保存</a>
                <a href="/EZine/Index" id="btnCancel">取消</a>
            </div>
            <div class="formItem">
            </div>
        </div>
        <div class="formsItems"></div>
    </div>
}

@section footer{
    <script type="text/javascript">
        $('#documentViewer').FlexPaperViewer(
            {
                config: {

                    SWFFile: $("#DocUrl").val(),
                    Scale: 0.6,
                    ZoomTransition: 'easeOut',
                    ZoomTime: 0.5,
                    ZoomInterval: 0.2,
                    FitPageOnLoad: true,
                    FitWidthOnLoad: false,
                    FullScreenAsMaxWindow: false,
                    ProgressiveLoading: false,
                    MinZoomSize: 0.4,
                    MaxZoomSize: 2,
                    SearchMatchAll: false,
                    InitViewMode: 'Portrait',
                    RenderingOrder: 'flash',
                    StartAtPage: '',

                    ViewModeToolsVisible: true,
                    ZoomToolsVisible: true,
                    NavToolsVisible: true,
                    CursorToolsVisible: true,
                    SearchToolsVisible: true,
                    WMode: 'window',
                    localeChain: 'zh_CN',
                    jsDirectory: "/Scripts/FlexPaper/js/",
                    cssDirectory: "/Scripts/FlexPaper/css/",
                    localeDirectory: "/Scripts/FlexPaper/locale/"
                }
            }
        );

        window.onunload = function setRemove() {
            var f = document.getElementById("documentViewer");
            if (f) {
                try { f.removeNode(true); } catch (e) { }
            }
        };
    </script>
}